<template>
    <div class="container">
        <h1>校园食堂代买餐平台</h1>
        <h2>管理员平台</h2>
        <v-container fluid class="px-4">
          <v-row no-gutters class="grid-container">
              <div class="section-title">投诉订单</div>
                <table>
                  <thead>
                    <tr>
                      <th>投诉编号</th>
                      <th>订单编号</th>
                      <th>投诉类型</th>
                      <th>投诉原因</th>
                      <th>处理意见</th>
                      <th>被投诉用户ID</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr v-for="item in orders" :key="item.OrderID" @click="isDeal(item)">
                      <td>{{ item.ComplaintID }}</td>
                      <td>{{ item.OrderID }}</td>
                      <td>{{ item.Type }}</td>
                      <td>{{ item.reason }}</td>
                      <td>{{ item.content }}</td>
                      <td>{{ item.complained }}</td>
                    </tr>
                  </tbody>
                </table>
          </v-row>
        </v-container>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';
const router = useRouter()

const orders = ref([])


onMounted(() => {
  console.log('mounted');
  const response = axios.get('http://localhost:8080/getComplaints')
  response.then(res => {  
    console.log(res.data);
    orders.value = res.data;
  })
});

const isDeal = (item) => {
  console.log(item);
  router.push({ name: 'dealComplaint', params: { ID: item.ComplaintID, OrderID: item.OrderID, Type: item.Type, reason: item.reason, content: item.content, complained: item.complained } })
}


</script>

<style scoped>
.container {
  max-width: 95%;
  margin: 2rem auto;
  overflow: hidden;
  text-align: center;
}

h1 {
  color: #333;
  margin-bottom: 20px;
}
h2 {
  color: #d15f1d;
  margin-bottom: 15px;
}
.login-options {
  margin-bottom: 20px;
}

.btn {
  display: inline-block;
  margin-top: 10px;
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  background-color: #5cb85c; /* 绿色按钮 */
  color: white;
  font-size: 16px;
  cursor: pointer;
  text-decoration: none;
  margin-right: 10px;
}

.btn:hover {
  background-color: #4cae4c; /* 鼠标悬停时的按钮颜色 */
}

/* 为容器添加一些内边距 */
.px-4 {
  padding-right: 16px;
  padding-left: 16px;
}

/* 移除列之间的间隙 */
.v-row.no-gutters {
  margin-right: 0;
  margin-left: 0;
}

/* 网格容器样式 */
.grid-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  margin-top: 2rem;
}

/* 网格项样式 */
.grid-item {
  background-color: #ffffff;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: var(--transition);
  overflow: auto;
  /* 添加相对定位，作为sticky表头的参考容器 */
  position: relative;
}

.grid-item:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* 框样式 */
.box {
  font-size: 1.5rem; /* 字体大小 */
  font-weight: bold; /* 字体加粗 */
  color: #333; /* 字体颜色 */
  margin-bottom: 16px; /* 与列表间距 */
  position: relative;
}

/* 列表样式 */
.request-list, .service-list {
  list-style-type: none; /* 移除列表项前的圆点 */
  padding: 0;
  width: 100%; /* 宽度 */
}

/* 列表项样式 */
.request-list li, .service-list li {
  font-size: 1rem; /* 字体大小 */
  line-height: 1.6; /* 行高 */
  color: #555; /* 字体颜色 */
  margin-bottom: 8px;
}

td{
  padding: 10px;
  border: 1px solid #ddd;
  text-align: center;
}

/* 表格容器样式 */
.table-container {
  position: relative;
  overflow-x: auto;
  margin-top: 1rem;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

/* 表格样式 */
table {
  margin-top: 10px;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

/* 表头样式 */
th {
  position: sticky;
  top: 0;
  background: linear-gradient(to bottom, #42b983, #3aa876);
  color: white;
  padding: 12px 8px;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
  z-index: 2;
}

/* 单元格样式 */
td {
  padding: 12px 8px;
  text-align: center;
  border-bottom: 1px solid #eee;
}

/* 表格行悬停效果 */
tr:hover {
  background-color: rgba(66, 185, 131, 0.05);
  cursor: pointer;
  transition: background-color 0.3s ease;
}

/* 标题样式 */
.section-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: #2c3e50;
  border-bottom: 2px solid #e9ecef;
  text-align: center;
  position: relative;
  width: 100%;
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 2px;
  background: linear-gradient(to right, transparent, #42b983, transparent);
}

/* 响应式调整 */
@media (max-width: 768px) {
  .table-container {
    margin: 0 -1rem;
  }
  
  td, th {
    padding: 8px;
    font-size: 0.9rem;
  }
}
</style>